package com.qilin.hscs.handle;

import com.qilin.hscs.enums.ResultEnum;
import com.qilin.hscs.exception.SMException;
import com.qilin.hscs.util.ResultVOUntil;
import com.qilin.hscs.vo.ResultVO;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class SMExceptionHandle{

    @ExceptionHandler(value = Exception.class)
    public ResultVO handle(Exception e){
        if(e instanceof SMException){
            SMException se=(SMException) e;
            return ResultVOUntil.error(se.getCode(),se.getMessage());
        }else{
            return ResultVOUntil.error(ResultEnum.SYSTEM_ERROR.getCode(),ResultEnum.SYSTEM_ERROR.getMsg());
        }

    }
}
